<template>
    <!-- 某测点一特征值最近500点波形图 -->
    <el-dialog :title="eigenvalue.name + ' ' + eigenvalue.unit" width="58%" :visible.sync="isShow" append-to-body :show-close="true">
        <div class="recentData" ref="recentData"></div>
    </el-dialog>
</template>
<script>
import { eigenvalueRecentApi } from '@/requset/api'
import { options } from './config'
import * as echarts from 'echarts'
export default {
    data() {
        return {
            options: null,
            isShow: false,
            recentData: [],

            eigenvalue: {
                name: '',
                unit: '',
            },
        }
    },

    props: ['sensorInfo'],
    methods: {
        //获取最近特征值数据
        eigenvalueRecent(obj) {
            return eigenvalueRecentApi(obj).then((res) => {
                if (res.data.code == 0) {
                    res.data.data.forEach((e2) => {
                        this.recentData.push([e2.time, e2.value])
                    })
                    this.isShow = true
                }
            })
        },
        showRecent(proj_no, saddr, sport, eigkey) {
            this.eigenvalueRecent({ proj_no, saddr, sport, eigkey }).then(() => {
                this.$nextTick(() => {
                    this.drawRecent()
                })
            })
        },
        drawRecent() {
            let ref = this.$refs.recentData
            let myChart = echarts.init(ref)
            if (myChart) myChart.clear()
            ref.removeAttribute('_echarts_instance_')
            let seriesData = []
            let obj = {
                data: this.recentData,
                type: 'line',
                symbolSize: 2, // 设置点的大小
            }
            seriesData.push(obj)

            this.options.series = seriesData
            this.options.xAxis.type = 'time'
            this.options.yAxis.name = '特征值'
            myChart.setOption(this.options)
            window.addEventListener('resize', function () {
                myChart.resize()
            })
        },
    },
    watch: {
        isShow: {
            handler(newVal) {
                if (!newVal) {
                    this.recentData = []
                }
            },
        },
    },
    created() {
        this.options = options
    },
}
</script>
<style lang="less" scoped>
.recentData {
    width: 100%;
    height: 60vh;
}
</style>
